<?php
   
	Class Vdos extends Public_Controller
	{
		function __construct()
		{
			parent::__construct();
		}	
		
		function index($id=FALSE)
		{
			//$this->template->set_layout('layout_blank');
			if(@$_GET['mode']=='all'){
				$vdos = new Vdo();		
				$data['vdos'] = $vdos->order_by('id','desc')->get_page();							
				$this->template->build('vdo_list',$data);
			}else{		
				if(empty($id)){
					$data['vdos'] = new Vdo();				
					$data['categories'] = new Category();
					(@$_GET['albumsearch'])?$data['categories']->like('name',$_GET['albumsearch']):'';
					(@$_GET['groups'])?$data['categories']->where('group_id',$_GET['groups']):'';
					$data['categories']->where("start_date <= date(sysdate()) and (end_date >= date(sysdate()) or end_date = date('0000-00-00')) and module = 'vdos' and parents <> 0 and status = 'approve'")->order_by('id','desc')->get_page();			    			 				
					$data['thumb_vdo'] = $data['vdos']->limit(4)->order_by("id","desc")->get();				
				}else{							
					$data['vdos'] = new Vdo();
					$data['categories'] = new Category();
					(@$_GET['category_id'])?$data['categories']->where('id',$_GET['category_id']):'';
					$data['categories']->where("start_date <= date(sysdate()) and (end_date >= date(sysdate()) or end_date = date('0000-00-00')) and module = 'vdos' and parents <> 0 and status = 'approve'")->where('group_id',$id)->order_by('id','desc')->get_page();
					$data['thumb_vdo'] = $data['vdos']->where("id <=".$id)->limit(4)->order_by("id","desc")->get();
				}
				$this->template->build('vdo_index',$data);
			}
		}
		
		function load_content($id=FALSE){
			$id = $_POST['id'];
			$type = $_POST['type'];
			$vdo = new Vdo($id);
			switch($type){
				case 'player':
					echo $vdo->vdo_script;
				break;
				case 'content':
					echo $vdo->title.'<br>'.$vdo->description;
				break; 
				case 'comment':
					echo $message = "";
				break;
			}
		}				
		
		function inc_home($id=FALSE)
		{
			$data['vdo'] = new Vdo();
			$data['vdo']->order_by("id","random")->get(1);
			$this->load->view('inc_home',$data);
		}

		function categories(){
			$data['vdo_categories'] = new Category();
			$data['vdo_categories']->where("start_date <= date(sysdate()) and (end_date >= date(sysdate()) or end_date = date('0000-00-00')) and module = 'vdos' and parents <> 0 and status = 'approve'")->order_by("id","desc")->get();
			
			$this->template->build('categories_view',$data);
		}

		function inc_index_index(){
			$data['vdos'] = $this->db->query("select vdos.id,vdos.category_id,vdos.cover_pic,vdos.title,vdos.vdo_script from vdos left join categories on vdos.category_id = categories.id where start_date <= date(sysdate()) and (end_date >= date(sysdate()) or end_date = date('0000-00-00')) and module = 'vdos' and parents <> 0 and status = 'approve' and index_show = 'yes' ORDER BY RAND() LIMIT 4")->result();
			$this->load->view('inc_index',$data);
		}

		function inc_district_index(){
			$data['vdos'] = $this->db->query("select vdos.id,vdos.category_id,vdos.cover_pic,vdos.title,vdos.vdo_script from vdos left join categories on vdos.category_id = categories.id where start_date <= date(sysdate()) and (end_date >= date(sysdate()) or end_date = date('0000-00-00')) and module = 'vdos' and parents <> 0 and status = 'approve' and tumbon_show = 'yes' ORDER BY RAND() LIMIT 4")->result();
			$this->load->view('inc_index',$data);
		}
		
		function inc_stat_index(){
			$data['vdos'] = $this->db->query("select vdos.id,vdos.category_id,vdos.cover_pic,vdos.title,vdos.vdo_script from vdos left join categories on vdos.category_id = categories.id where start_date <= date(sysdate()) and (end_date >= date(sysdate()) or end_date = date('0000-00-00')) and module = 'vdos' and parents <> 0 and status = 'approve' and stat_show = 'yes' ORDER BY RAND() LIMIT 4")->result();
			$this->load->view('inc_index',$data);
		}
		
		function inc_pms_index(){
			$data['vdos'] = $this->db->query("select vdos.id,vdos.category_id,vdos.cover_pic,vdos.title,vdos.vdo_script from vdos left join categories on vdos.category_id = categories.id where start_date <= date(sysdate()) and (end_date >= date(sysdate()) or end_date = date('0000-00-00')) and module = 'vdos' and parents <> 0 and status = 'approve' and pormor_show = 'yes' ORDER BY RAND() LIMIT 4")->result();
			$this->load->view('inc_index',$data);
		}
		
		function ajax_load_vdo(){
			if($_POST['id']){
				$vdo = new Vdo($_POST['id']);
				echo $vdo->vdo_script;
			}
		}
		
	}

?>